package com.shenjian.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shenjian.dao.AdminDao;
import com.shenjian.entity.Admin;
import com.shenjian.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
//住在类头,说明所有方法都带有事务,也可以注在方法上,默认发生运行时异常回滚数据
//增删改要加事务,查可以不加
@Transactional(rollbackFor = Exception.class)
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminDao adminDao;

    @Override
    public List<Admin> list() {
        return adminDao.select();
    }

    @Override
    public Map<String, Object> page(Integer pageNumber, Integer pageSize) {
        PageHelper.startPage(pageNumber, pageSize);
        PageInfo<Admin> pageInfo = new PageInfo<>(adminDao.select());
        Map<String, Object> map = new HashMap<>();
        map.put("list", pageInfo.getList());
        map.put("total", pageInfo.getTotal());
        map.put("pages", pageInfo.getPages());
        return map;
    }
}
